﻿using System.ComponentModel;
using System.IO;

namespace SlideShowDFG2
{
    public class Slide : INotifyPropertyChanged
    {
        public Slide()
        {
            
        }

        private string _title;
        private string _description;
        private string _source;
        private string _thumbnail;
        private string _tempPreviewFile;
        
        public event PropertyChangedEventHandler PropertyChanged;

        public string Title
        {
            get
            {
                if (string.IsNullOrEmpty(_title)) return string.Empty;
                else return _title;
            }
            set
            { 
                _title = value;
                OnPropertyChanged("Title");
            }
        }

        public string Description
        {
            get
            {
                if (string.IsNullOrEmpty(_description)) return string.Empty;
                else return _description;
            }
            set
            { 
                _description = value;
                OnPropertyChanged("Description");
            }
        }

        public string Source
        {
            get
            {
                if (string.IsNullOrEmpty(_source)) return string.Empty;
                else return _source;
            }
            set
            { 
                _source = value;
                OnPropertyChanged("Source");
            }
        }

        public string Thumbnail
        {
            get
            {
                if (string.IsNullOrEmpty(_thumbnail)) return string.Empty;
                else return _thumbnail;
            }
            set
            {
                _thumbnail = value;
                OnPropertyChanged("Thumbnail");
            }
        }

        public string TempPreviewFile
        {
            get { return _tempPreviewFile; }
            set { _tempPreviewFile = value; }
        }

        public bool IsVideoFile()
        {
            string ext = Path.GetExtension(_source);
            bool isVideo = false;
            foreach (string videoExt in VideoHelper.VIDEO_EXTENTSIONS)
            {
                if (videoExt == ext)
                {
                    isVideo = true;
                    break;
                }
            }
            return isVideo;
        }
        
        protected void OnPropertyChanged(string name)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null) handler(this, new PropertyChangedEventArgs(name));
        }
    }
}
